import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// import eslintPlugin from "vite-plugin-eslint";
import path from "path";

const aliasPath = (dir) => path.resolve(__dirname, dir);

export default defineConfig({
  plugins: [vue()],
  server: {
    hmr: true,
    host: '0.0.0.0', // 可以通过本地IP访问
    proxy: {
      "/api": {
        target: "http://192.168.1.111:3000", // 后端服务实际地址
        changeOrigin: true, // 是否改变源
        rewrite: (path) => path.replace(/^\/api/, ""), // 重写请求路径
      },
    },
  },
  resolve: {
    alias: {
      "@": aliasPath("/src"),
      api: aliasPath("/src/api"),
      ast: aliasPath("/src/assets"),
      com: aliasPath("/src/components"),
      libs: aliasPath("/src/libs"),
      route: aliasPath("/src/route"),
      store: aliasPath("/src/store"),
      sty: aliasPath("/src/styles"),
      views: aliasPath("/src/views"),
    },
  },
});
